package com.spzx.product.api;

import com.spzx.common.core.constant.SecurityConstants;
import com.spzx.common.core.constant.ServiceNameConstants;
import com.spzx.common.core.domain.R;
import com.spzx.common.core.web.page.TableDataInfo;
import com.spzx.product.api.domain.*;
import com.spzx.product.api.domain.vo.SkuStockVo;
import com.spzx.product.api.factory.RemoteProductFallbackFactory;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@FeignClient(contextId = "remoteProductService",value = ServiceNameConstants.PRODUCT_SERVICE,fallbackFactory = RemoteProductFallbackFactory.class)
public interface RemoteProductService {
    @GetMapping("/product/getTopSale")
    public R<List<ProductSku>> getTopSale(@RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    @Operation(summary = "商品列表搜索")
    @GetMapping("/product/skuList/{pageNum}/{pageSize}")
    public R<TableDataInfo> skuList(
            @PathVariable("pageNum") Integer pageNum,   //多个参数找ProductController上面参数是根据命名参数去找的,所以这里一定要个参数命名
            @PathVariable("pageSize") Integer pageSize,
            @SpringQueryMap SkuQuery skuQuery,         //@SpringQueryMap这个注解作用：就是告诉openfeign构建远程调用请求，将对象数据，以路径参数的方式进行传递。
            @RequestHeader(SecurityConstants.FROM_SOURCE)String source);

    //====================商品详情六个接口=======================
    @GetMapping("/product/getProductSku/{skuId}")
    public R<ProductSku> getProductSku(@PathVariable("skuId")Long skuId,@RequestHeader(SecurityConstants.FROM_SOURCE)String source);

    @GetMapping("/product/getProductInfo/{id}")
    public R<Product> getProductInfo(@PathVariable("id") Long id,@RequestHeader(SecurityConstants.FROM_SOURCE)String source);

    @GetMapping("/product/getSkuPrice/{skuId}")
    public R<SkuPrice> getProductSkuPrice(@PathVariable("skuId") Long skuId,@RequestHeader(SecurityConstants.FROM_SOURCE)String source);

    @GetMapping("/product/getProductDetails/{productId}")
    public R<ProductDetails> getProductDetails(@PathVariable("productId") Long productId,@RequestHeader(SecurityConstants.FROM_SOURCE)String source);

    @GetMapping("/product/getSkuSpecInfo/{productId}")
    public R<Map<String,Long>> getSkuSpecInfo(@PathVariable("productId") Long productId,@RequestHeader(SecurityConstants.FROM_SOURCE)String source);

    @GetMapping("/product/getSkuStock/{skuId}")
    public R<SkuStockVo> getSkuStock(@PathVariable("skuId") Long skuId, @RequestHeader(SecurityConstants.FROM_SOURCE)String source);
    //======================END================================

    //批量获取商品sku最新价格信息
    @PostMapping(value = "/product/getSkuPriceList")
    public R<List<SkuPrice>> getSkuPriceList(@RequestBody List<Long> skuIdList,@RequestHeader(SecurityConstants.FROM_SOURCE)String source);


    @PostMapping("/product/checkAndLock/{orderNo}")
    public R<String> checkAndLock(@PathVariable("orderNo") String orderNo, @RequestBody List<SkuLockVo> skuLockVoList,@RequestHeader(SecurityConstants.FROM_SOURCE)String source);
}
